package com.bestescortbedsystem.service.impl;

import com.bestescortbedsystem.dao.*;
import com.bestescortbedsystem.entity.*;
import com.bestescortbedsystem.service.ReportService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Resource
    private SesUserReportDao sesUserReportDao;
    @Resource
    private SesUserDao sesUserDao;
    @Resource
    private SesUserFeedbackDao sesUserFeedbackDao;
    @Resource
    private SesUserOrderDao sesUserOrderDao;
    @Resource
    private SesBedMessageDao sesBedMessageDao;
    @Resource
    private SesHospitalinfoDao sesHospitalinfoDao;
    @Resource
    private SesHospitalinfoDepartmentDao sesHospitalinfoDepartmentDao;

    @Override
    public Map<String, Object> getAllReport(Integer pageSize, Integer pageNum, Long reportId, Long userId, String reportStatus) {
        SesUserReportExample sesUserReportExample = new SesUserReportExample();
        SesUserReportExample.Criteria criteria = sesUserReportExample.createCriteria();
        PageHelper.startPage(pageNum,pageSize);
        if (reportId != null && !reportId.equals("")) {
            criteria.andReportidEqualTo(reportId);
        }
        if (reportStatus != null && !reportStatus.equals("")) {
            criteria.andReportstatusEqualTo(reportStatus);
        }
        if (userId!=null && !userId.equals("")){
            criteria.andUseridEqualTo(userId);
        }
        List<SesUserReport> sesUserReports=new ArrayList<>();
        if(reportId==null&&userId==null&&reportStatus.equals("")){
            sesUserReports=sesUserReportDao.selectByExample(null);
        }else {
            sesUserReports = sesUserReportDao.selectByExample(sesUserReportExample);
        }
        System.out.println("******************");
        for (SesUserReport s:sesUserReports){
            System.out.println(s);
        }
        System.out.println("******************");

        PageInfo<SesUserReport> pageInfo=new PageInfo<>(sesUserReports);
        Map<String,Object> map=new HashMap<>();
        map.put("page",pageInfo);

        List<SesUserFeedback> sesUserFeedbackList=sesUserFeedbackDao.selectByExample(null);
        map.put("sesUserFeedbackList",sesUserFeedbackList);

        List<SesUserOrder> sesUserOrderList=sesUserOrderDao.selectByExample(null);
        map.put("sesUserOrderList",sesUserOrderList);

        List<SesBedMessage> sesBedMessageList=sesBedMessageDao.selectByExample(null);
        map.put("sesBedMessageList",sesBedMessageList);

        List<SesHospitalinfo> sesHospitalinfoList = sesHospitalinfoDao.selectByExample(null);
        map.put("sesHospitalinfoList", sesHospitalinfoList);

        List<SesHospitalinfoDepartment> sesHospitalinfoDepartmentList = sesHospitalinfoDepartmentDao.selectByExample(null);
        map.put("sesHospitalinfoDepartmentList",sesHospitalinfoDepartmentList);

        //查询所有维修人员
        SesUserExample sesUserExample = new SesUserExample();
        sesUserExample.createCriteria().andUsertypeEqualTo(2);
        List<SesUser> sesUserList = sesUserDao.selectByExample(sesUserExample);
        map.put("weixiu", sesUserList);

        return map;
    }

    @Override
    public void deleteReport(Long reportId) {
        sesUserReportDao.deleteByPrimaryKey(reportId);
    }
}
